package standard

import (
	"github.com/gin-gonic/gin"
	"reflect"
)

type Router struct {
	Group *gin.RouterGroup
}

func NewRouter(group *gin.RouterGroup) *Router {
	return &Router{Group: group}
}
func (r Router) DefaultRouter(controller IController) {
	t := reflect.TypeOf(controller)
	for t.Kind() == reflect.Ptr {
		t = t.Elem()
	}
	if t.Kind() != reflect.Struct {
		panic("Called struct with a value that is not a pointer to an Controller struct")
	}
	r.Group.POST(t.Name(), controller.Create)
	r.Group.DELETE(t.Name()+"/:id", controller.Create)
	r.Group.PUT(t.Name()+"/:id", controller.Update)
	r.Group.PATCH(t.Name()+"/:id/state", controller.Update)
	r.Group.GET(t.Name(), controller.Get)
	controller.ExtendPath(r.Group)
}
